package com.heima.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    
    @Value("${upload.base-path}")
    private String basePath;
    
    @Value("${upload.access-prefix}")
    private String accessPrefix;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 将上传路径映射为静态资源路径
        String pathPattern = accessPrefix.replace("http://localhost:9999", "") + "/**";
        String resourceLocations = "file:" + basePath + "/";
        
        registry.addResourceHandler(pathPattern)
                .addResourceLocations(resourceLocations);
    }
}